<?php
/**
 * 数据库操作示例
 *
 * @package     controller
 * @author      Akon(番茄红了) <aultoale@gmail.com>
 * @copyright   Copyright (c) 2008 (http://www.imeelee.com)
 * @license     http://www.gnu.org/licenses/gpl.html     GPL 3
 */
class DbController extends Ext_Controller_Action
{

    /**
     *  Db Model
     *
     * @var ExampleModel
     */
    protected $_model = null;

    /**
     * 初始化方法
     */
    public function init()
    {
        $this->_model = new DbModel();
    }

    /**
     * 数据列表及分页
     */
    public function listAction()
    {
        $this->view->title = '数据列表及分页';
        $this->view->paginator = EGP_Paginator::factory($this->_model->listSql(), 1); //每页只显示一条记录
    }

    /**
     * 插入数据及表单验证
     */
    public function insertAction()
    {
        $this->view->title = '插入数据及表单验证';
        if ($this->request->isPost()) {
            try {
                $this->_model->insert($this->request->getPost());
                $this->view->feedback(array(
                    'message' => '数据插入成功',
                    'redirect' => $this->url(array('controller' => 'db', 'action' => 'insert'), true),
                    'linktext' => '点击继续',
                ));
            } catch (Exception $e) {
                $this->view->feedback(array(
                    'title'    => '发生错误',
                    'message'  => '操作失败：' . $e->getMessage(),
                ));
            }
        }
    }

    /**
     * 更新数据
     */
    public function updateAction()
    {
    }

}